import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ReplyMoodActionRecord } from 'src/app/model/reply-mood-action-record';
import { ReplyMoodVo } from 'src/app/model/reply-mood-vo';
import { QuickReplyDataService } from 'src/app/services/quick-reply-data.service';
@Component({
  selector: 'app-reply-item-mood-embed',
  templateUrl: './reply-item-mood-embed.component.html',
  styles: [``]
})
export class ReplyItemMoodEmbedComponent implements OnInit {
  @Input('mood')
  public replyMood!: ReplyMoodVo;
  @Output('moodAction')
  public moodActionEvent: EventEmitter<ReplyMoodActionRecord>;
  
  constructor(private replyIdShare: QuickReplyDataService) {
    this.moodActionEvent = new EventEmitter<ReplyMoodActionRecord>();
  }

  ngOnInit(): void {
  }

  //喜欢
  public onLiked(event: Event): void {
    //console.log('[ReplyItemMood-EMD] click like');
    this.toggleMood(true);
  }

  //讨厌
  public onHated(event: Event): void {
    //console.log('[ReplyItemMood-EMD] click hate');
    this.toggleMood(false);
  }

  private toggleMood(moodValue:boolean){
    //console.log('[ReplyItemMood-EMD] click value:'+moodValue);
    if(this.replyMood){
      //将统计信息传递到父组件(DetailComponent)
      this.moodActionEvent.emit({threads:this.replyMood.threads, reply:this.replyMood.reply, value:moodValue});
    }else{
      console.log('[ReplyItemMood-EMD] reply mood is lost');
    }
  }

  //快速回复事件
  public onQuickReply(replyId:number):void{
    this.replyIdShare.send(replyId);
  }
}
